<?php
Globals::requireController('Admin');
Globals::requireTable('AclResource');

class AclResourceController extends AdminController
{
	protected $aclResourceTable;
	
	public function __construct($config = null)
	{
		parent::__construct($config, 'acl_resource');
		$this->aclResourceTable = new AclResourceTable($config);
	}
	
	public function indexAction()
	{
		$this->view->data = $this->aclResourceTable->listAll(null, 'id ASC');
	}
	
	public function addAction()
	{
	}
	
	public function addPostAction()
	{
		$id = $this->aclResourceTable->add($this->getParams('name,description'), true);
		$this->log('添加权限对象'.($id ? '成功(id: '.$id.')' : '失败'));
		$this->redirectToAction();
	}
	
	public function modifyAction()
	{
		$id	= $this->getIntParam('id');
		$row= $this->aclResourceTable->getRow($id);
		
		if (!$row)
			Globals::error('权限对象ID无效。');
		
		$this->view->row = $row;
	}
	
	public function modifyPostAction()
	{
		$id = $this->getIntParam('id');
		$result = $this->aclResourceTable->modify($this->getParams('name,description'), $id);
		$this->log('修改权限对象'.($result ? '成功' : '失败').'(id: '.$id.')');
		$this->redirectToAction();
	}
	
	public function deleteAction()
	{
		$id = $this->getIntParam('id');
		$result = $this->aclResourceTable->delete($id);
		$this->log('删除权限对象'.($result ? '成功' : '失败').'(id: '.$id.')');
		$this->redirectToAction();
	}
}
